import request from '../request'
import qs from 'querystring'
import api from '../../config/api'
if (process.env.NODE_ENV === 'production') {
  request.defaults.baseURL = 'https://3d.cifuwu.com';
} else {
  request.defaults.baseURL = 'https://3d.cifuwu.com';
}

export function getProductList(tag, visible,p,n) {
    return request({
        url: api.products,
        method: 'get',
        params: {
            tag,
            visible,
            p,
            n
        }
    })
}
//获取元件信息
export function component(hash) {
    return request({
        url: api.element_details,
        method: 'get',
        params: {
            hash
        }
    })
}


export function getProductDetail(pid) {
  return request({
    url: api.product,
    method: 'get',
    params: {
      pid
    }
  })
}

//获取产品详细信息
export function details(pid) {
    return request({
        url: api.product_details,
        method: 'get',
        params: {
            pid
        }
    })
}
//保存产品
export function adminAdd(name,description,tags,thumbnail,price,visible,d3id,url,cid,rich_text,album){
  return request({
    url: api.admin_add,
    method: 'post',
    params: {
      name,
      description,
      tags,
      thumbnail,
      price,
      visible,
      d3id,
      url,
      cid,
      rich_text,
      album,
    }
  })
}
//产品列表
export function get_product_list(cid,p,n,orderby) {
    return request({
        url: api.product_list,
        method: 'post',
        data: {
            cid,
            p,
            n,
            orderby
        }
    })
}
//图片上传
export function loadimage(file) {
  return request({
    url: api.upload_images,
    method: 'post',
    data: {
      file
    }
  })
}
//保存模型元件
export function saveUnit(hash,format,name,tags,type,uv_mask){
  return request({
      url: api.admin_saveUnit,
      method : 'post',
      params :{
          hash,
          format,
          name,
          tags,
          type,
          uv_mask
      }
  })
}
//元件列表
export function element_list(p,n) {
    return request({
        url: api.element_list,
        method: 'post',
        data: {

            p,
            n
        }
    })
}
export default {
  getProductList: (...args) => getProductList(...args),
  getProductDetail: (...args) => getProductDetail(...args),

  adminAdd: (...args) => adminAdd(...args),
  loadimage: (...args) => loadimage(...args),
  saveUnit: (...args) => saveUnit(...args),
  component: (...args) => component(...args),
  details: (...args) => details(...args),
  get_product_list: (...args) => details(...args),
  element_list: (...args) => element_list(...args)
}
